<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
    class User{
        
        function connectData()
        {
            $con = mysql_connect("localhost","root", "" );
            if (!$con)
            {
                die('Dont connect to Database: ' . mysql_error());
            }
            mysql_select_db("abc", $con);
        }


        function  getUserDetail(){
            $this->connectData();
            $query = "SELECT * FROM User";
            $result = mysql_query($query) or die("Your ERROR CODE");
            
            $user = array();
            $i = 0;
            $num = mysql_num_rows($result);
            while ($i < $num) {
                $user[i] = array(
                    'UserId'=> mysql_result($result, $i, "Id"),
                    'UserName' => mysql_result($result, $i, "Name"),
                    'Email' => mysql_result($result, $i, "Email")
                );
                $i++;
            }
            return $user;
        }
        
        function insertUser($name,$email)
        {
            $finish = "Finished";
            $fail = "Failed";
            $this->connectData();
            $query = "insert into User (Name, Email) values ('$name', '$email')";
            $result = mysql_query($query);
            if($result)
                return $finish;
            else return $fail;
        }
    }
?>
